//
//  AccountViewController.m
//  jungoo
//
//  Created by Dang Quang Trung on 8/7/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "AccountViewController.h"
#import "AppDelegate.h"
#import "User.h"

@implementation AccountViewController
@synthesize emailLabel,emailContent;

-(void)initNavigationBar 
{
    self.navigationController.navigationBar.hidden = NO;
    
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
    UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 320, 1)];
    [overlayView setBackgroundColor:[UIColor whiteColor]];
    [self.navigationController.navigationBar addSubview:overlayView]; // navBar is your UINavigationBar instance
    [overlayView release];
    
    UIButton *BtnBack = [UIButton buttonWithType:UIButtonTypeCustom];
    BtnBack.frame = CGRectMake(0, 0, 29, 29);
    [BtnBack setImage:[UIImage imageNamed:@"back-button.png"] forState:UIControlStateNormal];
    [BtnBack addTarget:self action:@selector(backPressed) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:BtnBack];
    //[BtnBack release];
    self.navigationItem.leftBarButtonItem =backItem;
    [backItem release];
    
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"home_bg.png"]]]; 
}
- (void)applyTitle:(NSString*)title
{       
    UILabel * label = [[[UILabel alloc] initWithFrame:CGRectMake(0,0,320,43)] autorelease];
	label.textColor = [UIColor blackColor];
	label.backgroundColor = [UIColor clearColor]; 
	label.text = title;
    label.textColor = [UIColor colorWithRed:0.573 green:0.573 blue:0.573 alpha:1];
	self.navigationItem.titleView = label;
	[label sizeToFit];    
}
-(void) backPressed 
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [self initNavigationBar];    
    [self applyTitle:@"Account"];
    emailLabel.textColor = [UIColor colorWithRed:0. green:0.678 blue:0.941 alpha:1];
    emailContent.textColor = [UIColor colorWithRed:0.573 green:0.573 blue:0.573 alpha:1];
    emailContent.text = [[JGoUtility sharedCreateAccount] objectForKey:@"email"];

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void)dealloc{
    [emailLabel release];
    [emailContent release];
    [super dealloc];
}

-(IBAction)logout:(id)sender
{
    [self.navigationController dismissModalViewControllerAnimated:YES];
    if ([[AppDelegate shareDelegate]facebook] != nil) {
        [[[AppDelegate shareDelegate]facebook]logout];
    }
}
@end
